//package com.kssoft.demo.spider.head;
//
//import net.lightbody.bmp.BrowserMobProxy;
//import net.lightbody.bmp.BrowserMobProxyServer;
//import net.lightbody.bmp.client.ClientUtil;
//import net.lightbody.bmp.core.har.HarEntry;
//import net.lightbody.bmp.proxy.CaptureType;
//import net.lightbody.bmp.proxy.auth.AuthType;
//import org.openqa.selenium.Proxy;
//import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.chrome.ChromeOptions;
//import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.remote.CapabilityType;
//import org.openqa.selenium.remote.DesiredCapabilities;
//import org.springframework.boot.SpringApplication;
//import org.springframework.boot.autoconfigure.SpringBootApplication;
//
//import java.util.List;
//import java.util.Map;
//
//@SpringBootApplication
//public class BrowserMobProxyApplication {
//
//    public static void main(String[] args) {
//        SpringApplication.run(BrowserMobProxyApplication.class, args);
//
//        BrowserMobProxyServer mobProxyServer = new BrowserMobProxyServer();
//        mobProxyServer.setTrustAllServers(true);
//		mobProxyServer.autoAuthorization("", "","", AuthType.BASIC);
//
//	/*	//https://stackoverflow.com/questions/50775287/unable-to-perfrom-http-basic-auth-using-browsermob-proxy
//		String encodedCreadentials = "Basic " + (Base64.getEncoder().encodeToString("login:password".getBytes()));
//		proxy.addHeader("Authorization", encodedCreadentials);*/
//
//
//        mobProxyServer.start();
//
//
//        System.out.println("=================================================================");
//        System.out.println("This Execute Browser Port --> " + mobProxyServer.getPort());
//        System.out.println("=================================================================");
//
//        Proxy seleniumProxy = ClientUtil.createSeleniumProxy(mobProxyServer);
//        seleniumProxy.setHttpProxy("localhost:" + mobProxyServer.getPort());
//        seleniumProxy.setSslProxy("localhost:" + mobProxyServer.getPort());
//        mobProxyServer.newHar("douyin") ;
//
///*        DesiredCapabilities seleniumCapabilities = new DesiredCapabilities();
//        seleniumCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy);*/
//
//        ChromeOptions chromeOptions = new ChromeOptions();
//        chromeOptions.setProxy(seleniumProxy);
//        //System.setProperty("webdriver.gecko.driver","C:\\Users\\isa\\Desktop\\browser-mob-proxy\\browser-mob-proxy\\src\\main\\resources\\geckodriver.exe");
//        //WebDriver driver = new FirefoxDriver();
//        System.setProperty("webdriver.chrome.driver", "D:\\soft\\chromedriver-win64\\chromedriver.exe");
//        WebDriver driver = new ChromeDriver();
//
//        //proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
//
//        driver.get("https://www.baidu.com/s?wd=%E4%BC%8A%E6%9C%979%E5%90%8D%E6%A0%B8%E7%A7%91%E5%AD%A6%E5%AE%B6%E7%9D%A1%E8%A7%89%E6%97%B6%E8%A2%AB%E6%9A%97%E6%9D%80&sa=fyb_n_homepage&rsv_dl=fyb_n_homepage&from=super&cl=3&tn=baidutop10&fr=top1000&rsv_idx=2&hisfilter=1");
//        // 获取 HTTP 请求头
//        List<HarEntry> requestHeaders = mobProxyServer.getHar().getLog().getEntries();
//        System.out.printf("");
////        for (Map<String, String> headers : requestHeaders) {
////            String requestUrl = headers.get("url");
////            if (requestUrl.contains("example.com")) { // 过滤你想要的请求
////                Map<String, String> headerMap = headers.get("request").getHeaders();
////                String token = headerMap.get("Authorization");  // 这里假设 token 在 Authorization header 中
////                System.out.println("Token: " + token);
////            }
////        }
////        driver.close();
////        mobProxyServer.stop();
//    }
//
//
//}